<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="品牌名称">
              <j-input placeholder="请输入品牌名称" v-model="queryParam.brand"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="车型配置">
              <j-input placeholder="请输入车型配置" v-model="queryParam.carModel"></j-input>
              <!-- <a-date-picker placeholder="请输入车型配置" v-model="queryParam.carTypeConfiguration"></a-date-picker> -->
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :md="6" :sm="8">
              <a-form-item label="车辆vin码">
                <j-input placeholder="请输入车辆vin码" v-model="queryParam.vin"></j-input>
              </a-form-item>
            </a-col>
            
            <!-- <a-col :md="6" :sm="8">
              <a-form-item label="车辆颜色">
                <j-input placeholder="请输入车辆颜色" v-model="queryParam.outsideColor"></j-input>
              </a-form-item>
            </a-col>-->
            <a-col :md="6" :sm="8">
              <a-form-item label="合格证号码">
                <j-input placeholder="请输入合格证号码" v-model="queryParam.certificateNo"></j-input>
              </a-form-item>
            </a-col>
            <!-- <a-col :md="6" :sm="8">
              <a-form-item label="销售状态">
                <j-input placeholder="请输入销售状态" v-model="queryParam.carStatus"></j-input>
              </a-form-item>
            </a-col>-->
            <a-col :md="6" :sm="8">
              <a-form-item label="车辆存放库房">
                <a-select placeholder="请输入车辆存放库房" v-model="queryParam.storeId">
                  <a-select-option
                    :value="key"
                    v-for="(value,key) in storeName"
                    :key="key"
                  >{{ value }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="8">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button
                type="primary"
                @click="searchReset"
                icon="reload"
                style="margin-left: 8px"
              >重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
<!--      <a-button type="primary" icon="download" @click="handleExportXls('cxm-订单记录信息')">导出</a-button>-->
<!--      <a-upload-->
<!--        name="file"-->
<!--        :showUploadList="false"-->
<!--        :multiple="false"-->
<!--        :headers="tokenHeader"-->
<!--        :action="importExcelUrl"-->
<!--        @change="handleImportExcel"-->
<!--      >-->
<!--        <a-button type="primary" icon="import">导入</a-button>-->
<!--      </a-upload>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">
          批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @change="handleTableChange"
        :scroll="{ x: 2000 }"
      >
        <span slot="action" slot-scope="text, record">
          <a-button type="primary" @click="handleLook(record)" style="margin-right: 10px;">查看</a-button>
          <a-button type="primary" @click="handlePut(record)" style="margin-right: 10px;">修改</a-button>
          <a-button @click="showModal">作废</a-button>
          <a-modal v-model="visible2" title="作废提示" @ok="deleteId(record)">
            <p>是否对该条记录进行作废？作废后将无法恢复！</p>
          </a-modal>
        </span>
        <span
          slot="filterDepositAttribute"
          slot-scope="carStatus"
        >{{ carStatus | filterDepositAttribute(carStatus) }}</span>
      </a-table>
    </div>
    <!-- table区域-end -->
    <!-- 表单区域 -->
    <!-- <cxmOrderManager-modal ref="modalForm" @ok="modalFormOk"></cxmOrderManager-modal> -->
    <vehicle-register-model ref="modalForm" @ok="modalFormOk"></vehicle-register-model>
    <!-- <cxm-order-manager-info-modal ref="cxmOrderManagerInfoModal"></cxm-order-manager-info-modal> -->
    <vehicle-register-model-table ref="modalForm2" @ok="modalFormOk"></vehicle-register-model-table>
  </a-card>
</template>

<script>
import VehicleRegisterModel from './VehicleRegisterModel.vue'
import VehicleRegisterModelTable from './VehicleRegisterModelTable.vue'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JInput from '@/components/jeecg/JInput'
import moment from 'moment'
import { USER_INFO } from '@/store/mutation-types'
import Vue from 'vue'
import { getAction, httpAction } from '@/api/manage'
export default {
  name: 'VehicleRegister',
  mixins: [JeecgListMixin],
  components: {
    VehicleRegisterModel,
    VehicleRegisterModelTable,
    JInput,
    moment,
  },
  data() {
    return {
      description: 'cxm-订单管理页面',
      visible: false,
      visible2: false,
      // 表头
      loading: '',
      columns: [
        {
          title: '品牌名称',
          align: 'center',
          dataIndex: 'brand',
        },
        {
          title: '车型配置',
          align: 'center',
          dataIndex: 'carModel',
        },
        {
          title: '车辆vin码',
          align: 'center',
          dataIndex: 'vin',
        },
        {
          title: '车辆存放库房',
          align: 'center',
          dataIndex: 'storeName',
        },
        {
          title: '车辆颜色',
          align: 'center',
          dataIndex: 'outsideColor',
        },
        {
          title: '销售状态',
          align: 'center',
          dataIndex: 'carStatus',
          scopedSlots: {
            customRender: 'filterDepositAttribute',
          },
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: '240',
          fixed: 'right',
          scopedSlots: {
            customRender: 'action',
          },
        },
      ],

      url: {
        list: '/sale/cxmSaleCarInfo/list',
        delete: '/sale/cxmSaleCarInfo/delete',//通过id删除
        deleteBatch: '/sale/cxmSaleCarInfo/deleteBatch',//批量删除
        queryStoreMap: '/sale/cxmSaleStoreInfo/queryStoreMap',//查询仓库名
        exportXlsUrl: 'cxm/cxmSaleCarInfo/exportXls',//导入
        importExcelUrl: 'cxm/cxmSaleCarInfo/importExcel',//导出
      },
      storeName: {}
    }
  },
  created() {
    this.storeName = [];
    getAction(this.url.queryStoreMap).then((res) => {
      if (res.success) {
        this.storeName = res.result;
      }
    })
  },
  computed: {
    importExcelUrl: function () {
      return `${process.env.VUE_APP_BASE_API}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    showModal() {
      this.visible2 = true;
    },
    getInfo(record) {
      /* this.$refs.cxmOrderManagerInfoModal.showDrawer(record) */
    },
    deleteId(record) {
      console.log(record);
      let httpurl = this.url.delete + '?id=' + record.id;
      let formData = {}
      let method = 'post';

      httpAction(httpurl, formData, method).then((res) => {
        console.log(res);
        if (res.success) {
          console.log(res.result);
          this.visible2 = false;
          this.loadData();
        }else{
          this.$message.warning(res.message)
        }
      })
    },
    handleLook(record) {
      console.log(record);
      if (this.$refs.modalForm2.add) {
        this.$refs.modalForm2.add(record);
      } else {
        this.$refs.modalForm2.add = function (depart) {
          if (depart) {
            this.dictDisabled = false;
          } else {
            this.dictDisabled = true;
          }
          this.edit(depart);
        }
        this.$refs.modalForm2.add(record);
      }
      this.$refs.modalForm2.title = "查看";
      this.$refs.modalForm2.disableSubmit = false;
    },
    handlePut(record) {
      if (this.$refs.modalForm.add) {
        this.$refs.modalForm.add(record);
      } else {
        this.$refs.modalForm.add = function (depart) {
          if (depart) {
            this.dictDisabled = false;
          } else {
            this.dictDisabled = true;
          }
          this.edit(depart);
        }
        this.$refs.modalForm.add(record);
      }
      this.$refs.modalForm.title = "修改";
      this.$refs.modalForm.disableSubmit = false;
    }
  },
  filters: {
    filterTime(time) {
      return moment(time).format('YYYY-MM-DD')
    },
    filterDepositAttribute(depositAttribute) {
      switch (depositAttribute) {
        case 1:
          return "在库"
          break;
        case 2:
          return "已售"
          break;
        case 3:
          return "返厂"
          break;
        case 4:
          return "在售"
          break;
      }
    }
  },
}
</script>
<style scoped>
@import "~@assets/less/common.less";
</style>
